
//
//  BDHomeDetailCommentsModel.m
//  BadBoy
//
//  Created by wen on 2017/3/23.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDHomeDetailCommentsModel.h"

@implementation BDHomeDetailCommentsModel

+ (NSDictionary *)mj_replacedKeyFromPropertyName{
    return @{@"my_id":@"id",
             @"sub_comments":@"sub_comments.list",
             @"created_at":@"commented_at"};
}

+ (NSDictionary *)mj_objectClassInArray{
    return @{@"user":[BDUserModel class],
             @"reply_user":[BDUserModel class],
             @"sub_comments":[BDHomeDetailCommentsModel class]};
}

- (CGFloat)cellHeigth{
    return [self getyytextHeightWithText:self.comment] + [self getSubCommentsHeight] + 75;
}

- (CGFloat)contentHeight{
    return [self getyytextHeightWithText:self.comment];
}

- (CGFloat)subCommentHeight{
    return [self getSubCommentsHeight];
}

- (CGFloat)getyytextHeightWithText:(NSString *)text{
    NSMutableAttributedString *one = [[NSMutableAttributedString alloc] initWithString: text];
    one.font = [UIFont systemFontOfSize:14];
    YYTextLayout *layout = [YYTextLayout layoutWithContainer:[YYTextContainer containerWithSize:CGSizeMake(kBDScreenWidth - 60, MAXFLOAT)] text:one];
    return layout.textBoundingSize.height;
}

- (CGFloat)getSubCommentsHeight{
    CGFloat height = 0;
    for (BDHomeDetailCommentsModel *detailComment in self.sub_comments) {
        NSString *labelStr = nil;
        if (detailComment.reply_user != nil) {
            labelStr = [NSString stringWithFormat:ASLocalizedString(@"%@：回复%@ %@"), detailComment.user.nickname, detailComment.reply_user.nickname, detailComment.comment];
        }else{
            labelStr = [NSString stringWithFormat:@"%@：%@", detailComment.user.nickname, detailComment.comment];
        }
        NSMutableAttributedString *one = [[NSMutableAttributedString alloc] initWithString: labelStr];
        one.font = [UIFont systemFontOfSize:14];
        YYTextLayout *layout = [YYTextLayout layoutWithContainer:[YYTextContainer containerWithSize:CGSizeMake(kBDScreenWidth - 80, MAXFLOAT)] text:one];
        height += (layout.textBoundingSize.height + 10);
        [self.subCommentCellHeightArray addObject:@(layout.textBoundingSize.height + 10)];
    }
    return height;
}

- (NSMutableArray *)subCommentCellHeightArray{
    if (!_subCommentCellHeightArray) {
        self.subCommentCellHeightArray = [NSMutableArray array];
    }
    return _subCommentCellHeightArray;
}

@end
